home *** CD-ROM | disk | FTP | other *** search
- package com.extensibility.app;
-
- import com.extensibility.print.Printer;
- import com.extensibility.rock.BaseMenu;
- import com.extensibility.rock.Platform;
- import com.extensibility.rock.RAction;
- import com.extensibility.xml.URI;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Frame;
- import java.awt.Window;
- import java.awt.event.ActionEvent;
- import java.text.MessageFormat;
- import java.util.Date;
- import java.util.Enumeration;
- import java.util.EventObject;
- import javax.swing.AbstractAction;
- import javax.swing.AbstractButton;
- import javax.swing.JEditorPane;
- import javax.swing.JFrame;
- import javax.swing.JMenuBar;
- import javax.swing.JMenuItem;
- import javax.swing.SwingUtilities;
- import javax.swing.text.JTextComponent;
-
- public abstract class BaseWindow extends JFrame {
- BaseDocument document;
- protected JMenuBar menubar;
- protected BaseMenu muFile;
- protected BaseMenu muEdit;
- protected BaseMenu muWindows;
- protected BaseMenu muHelp;
- protected BaseMenu muNew;
- int insertPos = 0;
- int insertCount = 0;
- boolean needSeparator = true;
-
- public BaseWindow(BaseDocument var1) {
- this.document = var1;
- }
-
- public void initialize(ApplicationPreferences var1) {
- ((Component)this).setVisible(false);
- ((Window)this).addWindowListener(Desktop.getWindowListener());
- ((Frame)this).setIconImage(UI.getImage("ity.gif"));
- ((JFrame)this).setDefaultCloseOperation(0);
- this.setTitle();
- ((JFrame)this).setJMenuBar(this.createMenuBar());
- }
-
- public void performEdit(BaseEdit var1) {
- this.getDocument().performEdit(var1);
- }
-
- public static BaseWindow getWindow(Component var0) {
- return (BaseWindow)SwingUtilities.windowForComponent(var0);
- }
-
- public static BaseWindow getWindow(ActionEvent var0) {
- Object var1 = ((EventObject)var0).getSource();
- return var1 instanceof Component ? getWindow((Component)var1) : null;
- }
-
- public void setSize(int var1, int var2) {
- Dimension var3 = ((Component)this).getSize();
- Dimension var4 = ((JFrame)this).getRootPane().getSize();
- super.setSize(var1, var2);
- Dimension var5 = ((Component)this).getSize();
- int var6 = var5.width - var3.width;
- int var7 = var5.height - var3.height;
- Dimension var8 = ((JFrame)this).getRootPane().getSize();
- if (var4.equals(var8) && !var3.equals(var5)) {
- var8.width += var6;
- var8.height += var7;
- ((JFrame)this).getRootPane().setSize(var8);
- ((JFrame)this).getRootPane().revalidate();
- }
- }
-
- protected JMenuBar createMenuBar() {
- JMenuBar var1 = new JMenuBar();
- this.muFile = (BaseMenu)var1.add(new BaseMenu(UI.getString("menu.file")));
- this.muFile.setMnemonic(UI.getMnemonic("menu.file"));
- this.muNew = new BaseMenu(UI.getString("file.item.new"));
- String var2 = BaseApplication.getPreferences().getDefaultFileType();
- this.updateNewSubMenuItems(UI.getFileTypeName(var2));
- this.fillFileMenu();
- this.muEdit = (BaseMenu)var1.add(new BaseMenu(UI.getString("menu.edit")));
- this.muEdit.setMnemonic(UI.getMnemonic("menu.edit"));
- this.fillEditMenu();
- this.addOtherMenus(var1);
- this.muWindows = (BaseMenu)var1.add(new BaseMenu(UI.getString("menu.window")));
- this.muWindows.setMnemonic(UI.getMnemonic("menu.window"));
- this.fillWindowsMenu();
- this.muHelp = (BaseMenu)var1.add(new BaseMenu(UI.getString("menu.help")));
- this.muHelp.setMnemonic(UI.getMnemonic("menu.help"));
- this.fillHelpMenu();
- return var1;
- }
-
- protected void addOtherMenus(JMenuBar var1) {
- }
-
- protected void fillEditMenu() {
- this.createPreferencesAction().addToMenu(this.muEdit);
- }
-
- protected void fillHelpMenu() {
- this.createWelcomeAction().addToMenu(this.muHelp);
- this.muHelp.addSeparator();
- if (BaseApplication.isLaunchLimited()) {
- this.createPurchaseAction().addToMenu(this.muHelp);
- this.createRegisterAction().addToMenu(this.muHelp);
- this.muHelp.addSeparator();
- }
-
- this.createAboutAction().addToMenu(this.muHelp);
- }
-
- protected void fillFileMenu() {
- this.muFile.add(this.muNew);
- this.createOpenAction().addToMenu(this.muFile);
- this.createOpenURLAction().addToMenu(this.muFile);
- this.createCloseAction().addToMenu(this.muFile);
- this.createFileOpenSaveSeparator(this.muFile);
- this.createSaveAction().addToMenu(this.muFile);
- this.createSaveAsAction().addToMenu(this.muFile);
- this.createSaveToURLAction().addToMenu(this.muFile);
- this.createFileSavePrintSeparator(this.muFile);
- this.createPrintSetupAction().addToMenu(this.muFile);
- this.createPrintAction().addToMenu(this.muFile);
- this.muFile.addSeparator();
- this.createRecentMenuItems();
- this.createExitAction().addToMenu(this.muFile);
- }
-
- protected void createFileSavePrintSeparator(BaseMenu var1) {
- var1.addSeparator();
- }
-
- protected void createFileOpenSaveSeparator(BaseMenu var1) {
- var1.addSeparator();
- }
-
- public void fillWindowsMenu() {
- if (this.muWindows != null) {
- while(this.muWindows.getItemCount() > 0) {
- this.muWindows.remove(0);
- }
-
- this.createNewWindowAction().addToMenu(this.muWindows);
- this.muWindows.addSeparator();
- boolean var1 = true;
- Enumeration var2 = Desktop.getDocuments();
-
- while(var2.hasMoreElements()) {
- if (!var1) {
- this.muWindows.addSeparator();
- } else {
- var1 = false;
- }
-
- BaseDocument var3 = (BaseDocument)var2.nextElement();
- Enumeration var4 = Desktop.getWindowsOfDocument(var3);
-
- while(var4.hasMoreElements()) {
- BaseWindow var5 = (BaseWindow)var4.nextElement();
- this.muWindows.add(new 1(var5, (BaseWindow)null, ((Frame)var5).getTitle()));
- }
- }
-
- }
- }
-
- public BaseDocument getDocument() {
- return this.document;
- }
-
- final String getBaseTitle() {
- String var1 = UI.getString("window.title.format");
- String var2 = UI.getString(this.getClassName());
- String[] var3 = new String[]{this.getDocument().getName(), var2};
- return MessageFormat.format(var1, var3);
- }
-
- public void setTitle() {
- ((Frame)this).setTitle(this.getBaseTitle());
- }
-
- public BaseWindow getSyblingWindow(Class var1) {
- return Desktop.findWindow(new WindowMatchClass(this, var1));
- }
-
- protected void createRecentMenuItems() {
- this.insertPos = this.muFile.getItemCount();
- this.updateRecentMenuItems();
- }
-
- public void updateRecentMenuItems() {
- for(int var1 = this.insertCount; var1 > 0; --var1) {
- this.muFile.remove(this.insertPos);
- }
-
- this.insertCount = 0;
- int var3 = this.insertPos;
- int var2 = 0;
-
- while(true) {
- String var4 = BaseApplication.getPreference("RECENT.", var2 + 1);
- if (var4 == null || var4.length() == 0) {
- if (var2 > 0 && this.needSeparator) {
- this.muFile.addSeparator();
- this.needSeparator = false;
- } else if (var2 == 0 && !this.needSeparator) {
- this.muFile.remove(this.insertPos);
- this.needSeparator = true;
- }
-
- return;
- }
-
- ++this.insertCount;
- JMenuItem var5 = this.muFile.insert(this.createRecentAction(var2 + 1, new URI((URI)null, var4)), var3++);
- ((AbstractButton)var5).setMnemonic((new Integer(var2 + 1)).toString().charAt(0));
- ++var2;
- }
- }
-
- public void updateNewSubMenuItems(String var1) {
- this.muNew.removeAll();
- this.createNewAction(var1).addToMenu(this.muNew);
- }
-
- protected RAction createNewAction(String var1) {
- return new 2((BaseWindow)null, UI.getString("new.item.default", var1), 'N');
- }
-
- protected BaseAction createOpenAction() {
- return new 3((BaseWindow)null, "file.item.open", 'O');
- }
-
- protected BaseAction createOpenURLAction() {
- return new 4((BaseWindow)null, "file.item.open.url");
- }
-
- protected BaseAction createSaveToURLAction() {
- return new 5(this, "file.item.save.url");
- }
-
- protected BaseAction createCloseAction() {
- return new 6(this, "file.item.close", 'W');
- }
-
- public BaseAction createNewWindowAction() {
- return new 7(this, "item.newwindow");
- }
-
- protected AbstractAction createRecentAction(int var1, URI var2) {
- return new 8(var2, (BaseWindow)null, String.valueOf(String.valueOf(var1).concat(String.valueOf(" "))).concat(String.valueOf(var2.getShortName())));
- }
-
- public void updateToolBarView() {
- }
-
- protected RAction createSaveAction() {
- return new 9(this, "file.item.save", 'S');
- }
-
- protected RAction createSaveAsAction() {
- return new 10(this, "file.item.save.as");
- }
-
- protected RAction createPrintSetupAction() {
- return new 11(this, "file.item.print.setup");
- }
-
- protected RAction createPrintAction() {
- return new 12(this, "file.item.print", 'P');
- }
-
- protected RAction createExitAction() {
- return (RAction)(Platform.isMac() ? new 13((BaseWindow)null, "file.item.quit", 'Q') : new 14((BaseWindow)null, "file.item.exit"));
- }
-
- protected RAction createPurchaseAction() {
- return new 15(this, "help.item.purchase");
- }
-
- protected RAction createRegisterAction() {
- return new 16((BaseWindow)null, "help.item.register");
- }
-
- protected RAction createWelcomeAction() {
- return new 17((BaseWindow)null, "help.item.welcome");
- }
-
- public static RAction createHelpAction(String var0) {
- return new 18(var0, var0);
- }
-
- protected RAction createAboutAction() {
- return new 19((BaseWindow)null, "help.item.about");
- }
-
- protected RAction createPreferencesAction() {
- return new 20(this, "edit.item.preferences");
- }
-
- public abstract String getClassName();
-
- protected abstract String getText();
-
- public void printWindow(ActionEvent var1) {
- try {
- Printer var2 = new Printer();
- String var3 = this.getDocument().getName();
- var2.setHeader(String.valueOf(UI.getAppName()).concat(String.valueOf(" ")), "", UI.getString("print.file", var3));
- var2.setFooter((new Date()).toString(), "", UI.getString("print.page"));
- JEditorPane var4 = new JEditorPane("text/plain", this.getText());
- ((JTextComponent)var4).setEditable(false);
- var2.print(var3, var4, false);
- } catch (Exception var5) {
- DialogFactory.showException(this, 124, var5);
- }
-
- }
- }
-